package com.activiti6.demo.webservicetask;

import com.activiti6.demo.Activiti6DemoApplication;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
//import org.activiti.engine.impl.webservice.CxfWSDLImporter;
import org.activiti.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Activiti6DemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WebService2Test {

    @Autowired
    RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;


    @Test
    public void test() {
//        new CxfWSDLImporter();
        // 初始化参数
        Map<String, Object> vars = new HashMap<String, Object>();
        vars.put("nameVar", "mpc_test2");// 此处要wsdl里的nameVar，而不是流程里的name
        ProcessInstance pi = runtimeService.startProcessInstanceByKey(
                "service1", vars);
        System.out.println("流程启动成功，流程id:"+pi.getId() + "|execution id:" + pi.getSuperExecutionId());

//        // 完成第一个任务
//        Task task = taskService.createTaskQuery().singleResult();
//        taskService.complete(task.getId());

        // 输出调用Web Service后的参数
//        String add = (String) runtimeService.getVariable(pi.getId(), "addVar");
        ExecutionEntityImpl pi2 = (ExecutionEntityImpl)pi;
        String add = (String)pi2.getVariable("addVar");

        System.out.println("↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
        System.out.println();
        System.out.println();
        System.out.println("mpc_test现在居住的地点是—————————————————————————>" + add);
        System.out.println();
        System.out.println();
        System.out.println("↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑");




//        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("acitiviti.cfg.xml");
//        RepositoryService repositoryService=(RepositoryService) applicationContext.getBean("repositoryService");
//        RuntimeService runtimeService  = (RuntimeService) applicationContext.getBean("runtimeService");
//        IdentityService identityService=(IdentityService) applicationContext.getBean("identityService");
//        repositoryService.createDeployment().addClasspathResource("calculator.bpmn20.xml").deploy();
//
//        Map<String,Object> map=new HashMap<String,Object>();
//        map.put("input1", 2);
//        map.put("input2", 3);
//        ProcessInstance pi=runtimeService.startProcessInstanceByKey("process1", map);
//        System.out.println(pi.getId());
//
//
//        TaskService taskService = (TaskService) applicationContext.getBean("taskService");
//        taskService.claim("12", "yuyong");
//        taskService.complete("12");
//        int output = (Integer) runtimeService.getVariable("5", "output3");
//        System.out.println(output);
    }

}
